import ScorePanelConfig from '@config/ScorePanel';

// 定义记分牌的类
class ScorePanel {
    score: number;          // 分数
    level: number;          // 等级
    scoreEle: HTMLElement;  // 分数的元素
    levelEle: HTMLElement;  // 等级的元素
    maxLevel: number;       // 最高等级
    upScore: number;        // 多少分升一级

    constructor() {
        this.score = ScorePanelConfig.baseScore;
        this.level = ScorePanelConfig.baseLevel;
        this.scoreEle = document.querySelector('#score')!;
        this.levelEle = document.querySelector('#level')!;
        this.maxLevel = ScorePanelConfig.maxLevel;
        this.upScore = ScorePanelConfig.upScore;
    }

    // 设置一个加分的方法
    addScore() {
        this.score++;
        this.scoreEle.innerHTML = this.score + '';

        if(this.score % this.upScore === 0) {
            this.levelUp();
        }
    }

    // 提升等级的方法
    levelUp() {
        if(this.level < this.maxLevel) {
            this.level++;
            this.levelEle.innerHTML = this.level + '';
        }
    }
}

export default ScorePanel;